"""
(题目说明：为了不暴露赎金信字迹，要从杂志上搜索各个需要的字母，
组成单词来表达意思。杂志字符串中的每个字符只能在赎金信字符串中使用一次。)
ransomNote  赎金信
magazine    杂志
"""


class Solution:
    def canConstruct(self, ransomNote: str, magazine: str) -> bool:
        r = list(ransomNote)
        m = list(magazine)
        for i in range(0, len(m)):
            if m[i] in r:
                r.remove(m[i])
        if len(r) == 0:
            return True
        else:
            return False

    def canConstruct_1(self, ransomNote: str, magazine: str) -> bool:
        r_set = set(ransomNote)
        r_list = list(r_set)
        for char in r_list:
            if char not in magazine or ransomNote.count(char) > magazine.count(char):
                return False
        return True


if __name__ == '__main__':
    sou = Solution()
    print(sou.canConstruct("aaaa", "aaaab"))
    print(sou.canConstruct("aaaabc", "aaaab"))

    print(sou.canConstruct_1("aaaa", "aaaab"))
    print(sou.canConstruct_1("aaaabc", "aaaab"))
